//
//  ExpGoldCell.m
//  HuoBao
//
//  Created by sky on 15/12/3.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "ExpGoldCell.h"

#define OVERTIME_FIRCOLOR @"8b623b"
#define GetFinalResult(x,y,z,r) (IsIphone4?x:(IsIphone6P?r:(IsIphone5?y:z)))

#define MONEYFONT       GetFinalResult(26,26,30,30)
#define MONEYTOLEFT     GetFinalResult(16,16,21,21)

@implementation ExpGoldCell{
    UIImageView *_bgview;
    UILabel *_moneylbl;
    UILabel *_leixing;
    UILabel *_senddate;
    UILabel *_overdate;
    UIImageView *_overtime;
}


-(void)setIteminfo:(HBgetUserMoneyListIntemInfo *)iteminfo{
    _iteminfo = iteminfo;
    
    UIImage *zhuceim = [UIImage imageNamed:@"expgold_res"];
    UIImage *yaoim   = [UIImage imageNamed:@"expgold_fir"];
    UIImage *overim = [UIImage imageNamed:@"exgold_overtime"];
    
    if ([self.iteminfo.moneyType isEqualToString:@"1"]) {
        _bgview.image = zhuceim;
    }else if([self.iteminfo.moneyType isEqualToString:@"2"]){
        _bgview.image = yaoim;
    }
    
    NSString *money = [NSString stringWithFormat:@"￥%@",self.iteminfo.amountMoney];
    NSMutableAttributedString *nianhuaAtt = [[NSMutableAttributedString alloc]initWithString:money];
    NSRange nianhuaRange = [money rangeOfString:@"￥"];
    [nianhuaAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:nianhuaRange];
    _moneylbl.attributedText = nianhuaAtt;
    
    _leixing.text = self.iteminfo.moneyTitle;
    _senddate.text = [NSString stringWithFormat:@"发放日期：%@",self.iteminfo.giveDate];
    _overdate.text = [NSString stringWithFormat:@"到期日期：%@",self.iteminfo.expireDate];
    
    if ([self.iteminfo.effectStatus isEqualToString:@"0"]) {
        
    }else if([self.iteminfo.effectStatus isEqualToString:@"1"]){
        _overtime.image = overim;
    }
    
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self buildLayout];
    }
    return self;
}


-(void)buildLayout{
    UIImage *bgim = [UIImage imageNamed:@"expgold_fir"];
    _bgview = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, SCREEN_WIDTH - 30, bgim.size.height)];
    //bgview.image = bgim;
    [self.contentView addSubview:_bgview];
    
    
    _moneylbl = [self LabelWithRect:CGRectMake(MONEYTOLEFT, 0 , _bgview.width/2 - 21, _bgview.height) textColor:[LCCommon getColor:@"fa9838"] textstr:@"" textfont:MONEYFONT textstyle:NSTextAlignmentLeft];
    [_bgview addSubview:_moneylbl];
    

    
    UIImage *line = [UIImage imageNamed:@"expgold_doline"];
    UIImageView *linevi = [[UIImageView alloc]initWithFrame:CGRectMake(_bgview.width/2, _bgview.height/2 - line.size.height/2, line.size.width, line.size.height)];
    linevi.image = line;
    [_bgview addSubview:linevi];
    

    
    _leixing = [self LabelWithRect:CGRectMake(3 * _bgview.width/4 - 8 * 16/2, linevi.origin.y, _bgview.size.width - (3 * _bgview.width/4 - 8 * 16/2), 16) textColor:[LCCommon getColor:@"b1b1b1"] textstr:@"" textfont:16 textstyle:NSTextAlignmentLeft];
    [_bgview addSubview:_leixing];
    
    
    _senddate = [self LabelWithRect:CGRectMake(_leixing.origin.x, _leixing.origin.y + 16 + 10, _leixing.width, 11) textColor:[LCCommon getColor:@"666666"] textstr:@"" textfont:11 textstyle:NSTextAlignmentLeft];
    [_bgview addSubview:_senddate];
    
    
    _overdate = [self LabelWithRect:CGRectMake(_leixing.origin.x, _senddate.origin.y + 11 + 5, _leixing.width, 11) textColor:[LCCommon getColor:@"666666"] textstr:@"" textfont:11 textstyle:NSTextAlignmentLeft];
    [_bgview addSubview:_overdate];
    
    
    UIImage *overim = [UIImage imageNamed:@"exgold_overtime"];
    _overtime = [[UIImageView alloc]initWithFrame:CGRectMake(_senddate.origin.x + (_senddate.width/3 - overim.size.width/2), _senddate.origin.y, overim.size.width, overim.size.height)];
    //_overtime.image = overim;
    [_bgview addSubview:_overtime];
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



-(UILabel *)LabelWithRect:(CGRect)rect textColor:(UIColor *)color textstr:(NSString *)str textfont:(int)font textstyle:(NSTextAlignment)aligment{
    UILabel *label = [[UILabel alloc] initWithFrame:rect];
    label.textColor = color;
    label.text = str;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = aligment;
    label.numberOfLines = 0;
    return label;
}


@end
